package com.logansoft.zhxypkoa.domain.sys;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
//import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.context.annotation.Scope;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.logansoft.zhxypkoa.domain.Base;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 组织模型
 * 
 * @author zhuyj
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "s_sys_organization")
@Scope(value = "prototype")
public class Organization extends Base {

  private static final long serialVersionUID = 1L;
  /**
   * 父节点
   */
  @JsonIgnore
  @ManyToOne(targetEntity = Organization.class)
  @JoinColumn(name = "PARENT_ID")
  private Organization parent;
  /**
   * 子节点
   */
  @JsonIgnore
  @OneToMany(mappedBy="parent", cascade=CascadeType.REMOVE)
  private List<Organization> children;
  /**
   * 管理员
   */
  @OneToOne(targetEntity = User.class)
  @JoinColumn(name = "USER_ID")
  private User user;
  /**
   * 地址
   */
  @Column(name = "ADDRESS")
  private String address;
  /**
   * 包含的用户
   */
  @ManyToMany(mappedBy = "organizations", fetch = FetchType.LAZY)
  private List<User> users; 
  
  public Organization() {}
}
